angular.module("myKitchen")
    //这是购物车页面的内容
<<<<<<< HEAD
    .controller("cartController", function ($scope,singleService,homeService,classifyService) {

        //封装一个函数，当没有数据的时候，显示没有数据的样式，有数据显示另一个页面
        $scope.toggle = function () {
            if($scope.classShop[0] == null && $scope.homeShop[0] == null){
                return $scope.cartShow = false;
            }else{
                   return $scope.cartShow = true;
                    //$scope.cartAllPrice = function () {
                    //    for(var i=0; i< $scope.cartnum.length; i++){
                    //        $scope.allPrice +=  ($scope.cartnum[i].price*10000)*$scope.cartnum[i].cnt/10000
                    //    }
                    //    return($scope.allPrice.toFixed(2))
                    //}
                    //$scope.cart_length = function () {
                    //    return $scope.cartnum.length
                    //}
                    //$scope.allPrice;
                    ////购物车主页面的总价格
                    //$scope.cartAllPrice = function (item) {
                    //    return $scope.allPrice += item.price*item.count;
                    //}
                    //console.log($scope.allPrice)
             }
        }
        $scope.chang1=function(){
            $scope.bol1=false;
            $scope.bol2=true;
            $scope.bol3=true;
            $scope.bol4=true;
        }
=======
<<<<<<< HEAD
    .controller("cartController", function ($scope,singleService) {
=======
    .controller("cartController", function ($scope,singleService,homeService,classifyService) {
>>>>>>> 99b000400c4159366d0e78f1fb3ee2d53f9ba9ed
        $scope.chang1=function(){
           $scope.bol1=false;
           $scope.bol2=true;
           $scope.bol3=true;
           $scope.bol4=true;
       }
>>>>>>> bec7a032673b8195ffab065664db93dcb8254e41
        $scope.chang2=function(){
            $scope.bol2=false;
            $scope.bol1=true;
            $scope.bol3=true;
            $scope.bol4=true;
        }
        $scope.chang3=function(){
            $scope.bol3=false;
            $scope.bol1=true;
            $scope.bol2=true;
            $scope.bol4=true;
        }
        $scope.chang4=function(){
            $scope.bol4=false;
            $scope.bol1=true;
            $scope.bol3=true;
            $scope.bol2=true;
        }


<<<<<<< HEAD
        $scope.cartnum = singleService.sendcartItems();
        $scope.classShop = classifyService.getClassifyItems();

        $scope.homeShop = homeService.sendCarouselItems()
        console.log($scope.homeShop)
=======
        $scope.allPrice = 0;
        $scope.mum = [];
        $scope.mum = singleService.sendcartItems();
        console.log($scope.mum)
<<<<<<< HEAD

        $scope.cartAllPrice = function () {
            for(var i=0; i< $scope.mum.length; i++){
                console.log( typeof ($scope.mum.length))
                $scope.allPrice +=  ($scope.mum[i].price*10000)*$scope.mum[i].cnt/10000
                //console.log(typeof($scope.mum[i].price))
                console.log($scope.allPrice)
=======
        $scope.cartAllPrice = function () {
            for(var i=0; i< $scope.mum.length; i++){
                // console.log( typeof ($scope.mum.length))
                $scope.allPrice +=  ($scope.mum[i].price*10000)*$scope.mum[i].cnt/10000
                //console.log(typeof($scope.mum[i].price))
                // console.log($scope.allPrice)
>>>>>>> 99b000400c4159366d0e78f1fb3ee2d53f9ba9ed

            }
            return($scope.allPrice.toFixed(2))
        }
<<<<<<< HEAD
        $scope.cart_length = function () {
            return $scope.mum.length
        }

=======
        // $scope.cart_length = function () {
        //     return $scope.mum.length
        // }
		
		$scope.classShop = classifyService.getClassifyItems();
		$scope.homeShop = homeService.sendCarouselItems()
>>>>>>> 99b000400c4159366d0e78f1fb3ee2d53f9ba9ed
>>>>>>> bec7a032673b8195ffab065664db93dcb8254e41

    })
    //这是凑单页面的内容
    .controller("singleController", function ($scope,singleService) {
        singleService.getAllItems(function(res){
            $scope.goods = (res.data.items);
           var data = (res.data.items)
            return data;
        })
        $scope.jiadan = function (item) {
            console.log(item)
            var shopIdex = shoparr.indexOf(item);
            if(shopIdex==-1){
                shoparr.push(item);
            }else{
                shoparr[shopIdex] = item;
            }
            console.log(shoparr)
        }
        var allprice = 0;
        var shoparr = []
        //加加减减的运算
        $scope.add = function(item){
            item.cnt = item.cnt ? (item.cnt+1) : 1;
            if(item.cnt>6)
                item.cnt=6
            allprice =99- item.price*item.cnt;

        }
        $scope.sub = function(item){
            item.cnt = item.cnt && item.cnt>=0 && item.cnt-1;
        }

        //总价差多少的计算
        $scope.allPrice = function(){
<<<<<<< HEAD
=======
            //return ((99-allprice)*100)/100;
>>>>>>> bec7a032673b8195ffab065664db93dcb8254e41
            return allprice
        }

        $scope.add_shopcar = function(){
            singleService.getcartItems(shoparr);
        }
    })
    //这是新建收货地址的内容
    .controller("buildController", function ($scope,singleService) {
        $scope.name="";
        $scope.phone="";
        $scope.adres="";
        $scope.key="";
        $scope.aa="";
        $scope.preservation=function(name,phone,adres,key,aa){
            singleService.getAdress(name,phone,adres,key,aa);


        }
    })
    .controller("addressController", function ($scope,singleService) {
        var arr=singleService.sendItems()
        $scope.name=arr[0];
        $scope.phone=arr[1];
        $scope.adres=arr[2];
        $scope.key=arr[3];
        $scope.aa=arr[4];
<<<<<<< HEAD
=======
        console.log(singleService.sendItems());
>>>>>>> bec7a032673b8195ffab065664db93dcb8254e41
    })





//这是路由部分
    .config(function($stateProvider,$urlRouterProvider){
        //cart部分
        // 二级路由(点击填写地址到地址页)
        $stateProvider.state("cart_adres",{
            url:"/address",
            templateUrl:"view/second/address.html",
            controller:"addressController"
        })
        .state("single",{
            url:"/single",
            templateUrl:"view/second/single.html",
            controller:"singleController"
        })
        // 三级路由（点击新建到填写信息页）
        .state("build_address",{
            url:"/build_address",
            templateUrl:"view/third/build_address.html",
            controller:"buildController"
        })

        //由三级新建地址跳回二级地址页
        .state("return_address",{
            url:"/address",
            templateUrl:"view/second/address.html",
        })
    })